#!/usr/bin/python
import socket
import struct
if __name__ == '__main__':
	sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
	sock.bind(('localhost',9999))
	sock.listen(5)
	while True:
		try:
			connection,address = sock.accept()
			connection.settimeout(5)
			while True:
				buf = connection.recv(struct.calcsize('ii'))
				if buf == '':
					break
				a1,a2 = struct.unpack("ii",buf)
				print a1 , a2
		except socket.timeout:
			print "socket.timeout"
			connection.send('time out')
			break	
		except KeyboardInterrupt:
			print "Ctrl+C exception"
			break
		except:
			print "other exception"
			break
		connection.close()

	sock.close()
